package com.dt76.smallloanbackenduser.controller.lhuaw;

import com.dt76.smallloanbackenduser.remote.lhuaw.AppPushMessagetest;
import com.dt76.smallloanbackenduser.remote.lhuaw.StationLettertest;
import com.dt76.smallloanbackenduser.utils.Page;
import com.dt76.smallloanbackenduser.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/lhuaw")
public class AppPushMessageController {
    @Autowired
    private AppPushMessagetest appPushMessagetest;

    @RequestMapping("/qryAllApp")
    public String AppPushMessage1(Model model){
        model.addAttribute("AppPushMessageList",appPushMessagetest.qryAllApp());
        System.out.println("调用成功");
        System.out.println(appPushMessagetest.qryAllApp());
        return "pages/lhuaw/AppPushMessage";
    }

    @RequestMapping("/qryConditionPageAllApp")
    public String qryStationConditionPageAll(Model model,Integer currentPageNo,
                                             @RequestParam(value ="pushTitle",required = false)String pushTitle,
                                             @RequestParam(value = "appPublisher",required = false)String appPublisher
    ){
        if (currentPageNo <= 0) {
            currentPageNo = 1;
        }
        String stationpushTitle= "";
        String paramappPublisher="";
        if(pushTitle != null && ! pushTitle.equals("")){
            stationpushTitle ="%"+pushTitle+"%";
        }
        if(appPublisher !=null && ! appPublisher.equals("")){
            paramappPublisher ="%"+appPublisher+"%";
        }
        Page page = appPushMessagetest.qryConditionPageAllApp(currentPageNo,stationpushTitle,paramappPublisher);
        model.addAttribute("qryAppList",page.getRows());
        model.addAttribute("page",page);
        model.addAttribute("pushTitle",pushTitle);
        model.addAttribute("appPublisher",appPublisher);
        System.out.println(page.getRows());
        return "pages/lhuaw/AppPushMessage";
    }
    //删除
    @RequestMapping("/delApp/{appId}")
    @ResponseBody
    public Result delete(@PathVariable String appId){
        return appPushMessagetest.delApp(Integer.parseInt(appId));
    }
}
